<?php

abstract class Manager_Forms_Abstract extends Zend_Form
{

    public function __construct($options = null)
    {
        parent::__construct($options);
        $this->clearDecorators();
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'ul')),
            'Form',
        ));
        $this->changeDecoratorElements();
    }

    public function removeElements(array $elements)
    {
        if (count($elements) > 0):
            foreach ($elements as $element):
                $this->removeElement($element);
            endforeach;
        endif;
    }

    public function removeDecoratorAllElements()
    {
        $elements = $this->getElements();
        foreach ($elements as $element):
            $element->removeDecorator('Errors');
        endforeach;
    }

    public function getErrorsMessage(array $messages)
    {
        $viewError = array();
        foreach ($messages as $key => $elements):
            $nameElement = $this->getElement($key)->getLabel();
            foreach ($elements as $error):
                $viewError[$nameElement][] = $error;
            endforeach;
        endforeach;

        return $viewError;
    }
    
    public function changeDecoratorElements()
    {
        $elements = $this->getElements();
        foreach($elements as $element):
            if (($element instanceof Zend_Form_Element_File)):
                $element->setDecorators(
                        array(
                            'File',
                            'label',
                            array('htmlTag', array('tag' => 'li')),
                        )
                );

            else:
                $element->setDecorators(
                        array(
                            'viewHelper',
                            'label',
                            array('htmlTag', array('tag' => 'li')),
                        )
                );
            endif;
        endforeach;
        
    }

}